package com.example.administrator.capital.model;

import com.example.administrator.capital.R;
import com.example.administrator.capital.model.base.BaseModel;
import com.example.administrator.capital.model.base.IActionRequest;
import com.example.administrator.capital.model.bean.ErrorBean;
import com.example.administrator.capital.url.Url;
import com.example.administrator.capital.utils.JsonUtils;
import com.example.administrator.capital.utils.LogUtils;
import com.example.administrator.capital.utils.PreferenceManager;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

/**
 * Created by Administrator on 2017/12/22 0022.
 *  个人中心 model
 */

public class MineModel extends BaseModel {
    /**
     * @param iActionRequest
     * @param uid
     * 查询个人账户接口
     */
    public void oneMem(final IActionRequest<String> iActionRequest, String uid){
        OkGo.<String>post(Url.ONEMEM).tag(this).headers("TOKEN", PreferenceManager.instance().getToken()).params("uid",uid).execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                LogUtils.d("查询个人账户"+response.body());
                if (response.body().contains("\"code\":1")) {
                    iActionRequest.success(response);
                } else {
                    ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                    iActionRequest.failMsg(bean.getMsg());
                }
            }
            @Override
            public void onError(Response<String> response) {
                super.onError(response);
                iActionRequest.code(R.string.error_msg);
            }
        });
    }
    /**
     * @param iActionRequest
     * @param tel
     * @param paypass
     * @param Password
     * 修改个人账户接口
     */
    public void updateMem(final IActionRequest<String> iActionRequest,
                          String tel, String paypass, String Password){

        OkGo.<String>post(Url.UPDATEMEM).tag(this).headers("TOKEN", PreferenceManager.instance().getToken()).params("tel",tel)
                .params("paypass",paypass)
                .params("Password",Password).
                execute(new StringCallback() {
            @Override
            public void onSuccess(Response<String> response) {
                LogUtils.d("修改个人账户"+response.body());
                if (response.body().contains("\"code\":1")) {
                    iActionRequest.success(response);
                } else {
                    ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                    iActionRequest.failMsg(bean.getMsg());
                }
            }
            @Override
            public String convertResponse(okhttp3.Response response) throws Throwable {
                return super.convertResponse(response);
            }
            @Override
            public void onError(Response<String> response) {
                super.onError(response);
                iActionRequest.code(R.string.error_msg);
            }
        });
    }

    /**
     * @param iActionRequest
     * @param uid
     * 查询用户消息接口
     */
    public void selectMes(final IActionRequest<String> iActionRequest,
                          String uid){

        OkGo.<String>post(Url.SELECTMES).tag(this).headers("TOKEN", PreferenceManager.instance().getToken()).params("uid",uid)
              .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("查询用户消息"+response.body());
                        if (response.body().contains("\"code\":1")) {
                            iActionRequest.success(response);
                        } else {
                            ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                            iActionRequest.failMsg(bean.getMsg());
                        }
                    }
                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return super.convertResponse(response);
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        iActionRequest.code(R.string.error_msg);
                    }
                });
    }

    /**
     * @param iActionRequest
     * @param uid
     * 查询投资记录接口
     */
    public void investMent(final IActionRequest<String> iActionRequest,
                          String uid,int page,String status){

        OkGo.<String>post(Url.INVESTMENT).tag(this).headers("TOKEN", PreferenceManager.instance().getToken()).params("uid",uid).params("pageNo",page)
                .params("status",status)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("查询投资记录"+response.body());
                        if (response.body().contains("\"code\":1")) {
                            iActionRequest.success(response);
                        } else {
                            ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                            iActionRequest.failMsg(bean.getMsg());
                        }
                    }
                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return super.convertResponse(response);
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        iActionRequest.code(R.string.error_msg);
                    }
                });
    }

    /**
     * @param iActionRequest
     * @param uid
     * 查询我的账户接口
     */
    public void account(final IActionRequest<String> iActionRequest,
                           String uid){

        OkGo.<String>post(Url.ACCOUNT).tag(this).headers("TOKEN", PreferenceManager.instance().getToken()).params("uid",uid)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("查询我的账户接口"+response.body());
                        if (response.body().contains("\"code\":1")) {
                            iActionRequest.success(response);
                        } else {
                            ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                            iActionRequest.failMsg(bean.getMsg());
                        }
                    }
                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return super.convertResponse(response);
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        iActionRequest.code(R.string.error_msg);
                    }
                });
    }


    /**
     * @param iActionRequest
     * @param uid
     * 查询资金明细接口
     */
    public void capital(final IActionRequest<String> iActionRequest,
                        String uid){

        OkGo.<String>post(Url.CAPITAL).tag(this).headers("TOKEN", PreferenceManager.instance().getToken()).params("broadheading",uid)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("查询资金明细接口"+response.body());
                        if (response.body().contains("\"code\":1")) {
                            iActionRequest.success(response);
                        } else {
                            ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                            iActionRequest.failMsg(bean.getMsg());
                        }
                    }
                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return super.convertResponse(response);
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        iActionRequest.code(R.string.error_msg);
                    }
                });
    }


    /**
     * @param iActionRequest
     * @param uid
     * 跳转提现页面接口
     */
    public void withdrawals(final IActionRequest<String> iActionRequest,
                        String uid){
        OkGo.<String>post(Url.WITHDRAWALS).tag(this).headers("TOKEN", PreferenceManager.instance().getToken()).params("uid",uid)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("跳转提现页面"+response.body());
                        if (response.body().contains("\"code\":1")) {
                            iActionRequest.success(response);
                        } else {
                            ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                            iActionRequest.failMsg(bean.getMsg());
                        }
                    }
                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return super.convertResponse(response);
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        iActionRequest.code(R.string.error_msg);
                    }
                });
    }

    /**
     * @param iActionRequest
     * @param uid
     * 申请提现接口
     */
    public void applywithdrawals(final IActionRequest<String> iActionRequest,
                            String uid,String Cash,String bankselect,String paypass){
        OkGo.<String>post(Url.APPLYWITHDRAWALS).tag(this).headers("TOKEN", PreferenceManager.instance().getToken())
                .params("uid",uid).params("cash",Cash).
                params("bankselect",bankselect).params("paypass",paypass)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("申请提现"+response.body());
                        if (response.body().contains("\"code\":1")) {
                            iActionRequest.success(response);
                        } else {
                            ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                            iActionRequest.failMsg(bean.getMsg());
                        }
                    }
                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return super.convertResponse(response);
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        iActionRequest.code(R.string.error_msg);
                    }
                });
    }


    public void addbankcarduser(final IActionRequest<String> iActionRequest,
                                String uid,String bankname,
                                String Openname,String Bankaccount,String Accountname,String Bankcity,String Idnumber){
        OkGo.<String>post(Url.ADDBANKCARDUSER).tag(this).headers("TOKEN", PreferenceManager.instance().getToken())
                .params("uid",uid)
                .params("bankname",bankname)
                .params("Openname",Openname)
                .params("Bankaccount",Bankaccount)
                .params("Accountname",Accountname)
                .params("Bankcity",Bankcity)
                .params("Idnumber",Idnumber)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("银行卡确认添加接口"+response.body());
                        if (response.body().contains("\"code\":1")) {
                            iActionRequest.success(response);
                        } else {
                            ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                            iActionRequest.failMsg(bean.getMsg());
                        }
                    }
                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return super.convertResponse(response);
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        iActionRequest.code(R.string.error_msg);
                    }
                });
    }

    /**
     * 修改个人资料接口
     */
    public void updatemean(final IActionRequest<String> iActionRequest,
                                 String username,String realname,
                           String idnumber){
        OkGo.<String>post(Url.UPDATEMEAN).tag(this).headers("TOKEN", PreferenceManager.instance().getToken())
                .params("username",username)
                .params("realname",realname).
                params("idnumber",idnumber)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("修改个人资料接口"+response.body());
                        if (response.body().contains("\"code\":1")) {
                            iActionRequest.success(response);
                        } else {
                            ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                            iActionRequest.failMsg(bean.getMsg());
                        }
                    }
                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return super.convertResponse(response);
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        iActionRequest.code(R.string.error_msg);
                    }
                });
    }
    public void updatepassword(final IActionRequest<String> iActionRequest,
                                 String oldpass,String password){
        OkGo.<String>post(Url.UPDATEPASSWORD).tag(this).headers("TOKEN", PreferenceManager.instance().getToken())
                .params("oldpass",oldpass)
                .params("password",password)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("修改密码接口"+response.body());
                        if (response.body().contains("\"code\":1")) {
                            iActionRequest.success(response);
                        } else {
                            ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                            iActionRequest.failMsg(bean.getMsg());
                        }
                    }
                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return super.convertResponse(response);
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        iActionRequest.code(R.string.error_msg);
                    }
                });
    }
    public void updatepayword(final IActionRequest<String> iActionRequest,
                                 String yzm,String paypass,String tel){
        OkGo.<String>post(Url.UPDATEPAYWORD).tag(this).headers("TOKEN", PreferenceManager.instance().getToken())
                .params("yzm",yzm)
                .params("paypass",paypass)
                .params("tel",tel)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("修改支付密码接口"+response.body());
                        if (response.body().contains("\"code\":1")) {
                            iActionRequest.success(response);
                        } else {
                            ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                            iActionRequest.failMsg(bean.getMsg());
                        }
                    }
                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return super.convertResponse(response);
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        iActionRequest.code(R.string.error_msg);
                    }
                });
    }

    public void banklist(final IActionRequest<String> iActionRequest){
        OkGo.<String>post(Url.BANKLIST).tag(this).headers("TOKEN", PreferenceManager.instance().getToken()).params("uid",PreferenceManager.instance().getUseId())
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        LogUtils.d("银行卡列表"+response.body());
                        if (response.body().contains("\"code\":1")) {
                            iActionRequest.success(response);
                        } else {
                            ErrorBean bean = JsonUtils.parse(response.body(), ErrorBean.class);
                            iActionRequest.failMsg(bean.getMsg());
                        }
                    }
                    @Override
                    public String convertResponse(okhttp3.Response response) throws Throwable {
                        return super.convertResponse(response);
                    }
                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        iActionRequest.code(R.string.error_msg);
                    }
                });
    }
}
